package algorithmTopics.designPatterns.prototypePattern;

import java.util.HashMap;

/**
 * 形状缓存
 *
 * @author 86155
 * @date 2025/07/22
 */
public class ShapeCache {
    protected static HashMap<String, Shape> shapeMap = new HashMap<>();

    public static Shape getShape(String name) throws CloneNotSupportedException {
        return (Shape) shapeMap.get(name).clone();
    }

    public static void loadCache() {
        Square square = new Square();
        square.setName("1");
        shapeMap.put(square.getName(),square);

        Rectangle rectangle = new Rectangle();
        rectangle.setName("2");
        shapeMap.put(rectangle.getName(), rectangle);
    }

}
